<!doctype html>
<html class="no-js">
<head>
  	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
  	<meta name="description" content="">
  	<meta name="keywords" content="">
  	<meta name="viewport"content="width=device-width, initial-scale=1">
  	<meta name="renderer" content="webkit">
  	<meta http-equiv="Cache-Control" content="no-siteapp"/>
<!-- common -->
  	<link rel="stylesheet" href="../css/amazeui.min.css">
  	<link rel="stylesheet" href="../css/app.css">
    <link rel="stylesheet" href="../css/common.css">
  	<script src="../js/jquery.min.js"></script>
	<script src="../js/amazeui.min.js"></script>
    <script src="../js/common.js"></script>

    <!-- page -->
	<link rel="stylesheet" href="../css/registered.css">
    <link rel="stylesheet" href="../plugin/ld/css/style.css" />
    <script src="../js/plupload.full.min.js" charset="utf-8"></script>
    <script src="../js/md5.js" charset="utf-8"></script>
    <script src="../plugin/layer/layer.js"></script>

  	<title>修改密码</title>
</head>
<body style="padding-top:15px;">
    <form class="am-form">
  <fieldset>
    <legend>修改密码</legend>

    <div class="am-form-group">
      <label for="doc-ipt-text-1">手机号码</label>
      <input type="text" class="phone"  placeholder="请输入您的手机号码">
    </div>

    <div class="am-form-group">
      <label for="doc-ipt-text-1">验证码</label>
      <div>
         <input type="text" class="" id="yanzmtxt" placeholder="请输入验证码" style="width:70%;display:inline-block;">
        <button type="button" class="am-btn am-btn-danger" onclick="yanzhengma()" id="yanzhengmaBtn">发送</button>
      </div>
    </div>

    <div class="am-form-group">
      <label for="doc-ipt-pwd-1">输入您的新密码</label>
      <input type="password" class="" id="password" placeholder="设置个密码吧">
    </div>

    <p>
        <button type="button" class="am-btn am-btn-danger" style="width:100%;" onclick="save();">提交修改</button>
    </p>

  </fieldset>
</form>

</body>

<script type="text/javascript">
    var yzm,yzmStr;

    // 发送验证码
    function yanzhengma(){
        if($('#yanzhengmaBtn').html() == '发送'){

            var phone = $('.phone').val(); // 手机号
            var phoneLen = $('.phone').val().length; //手机号长度

            // 判断手机号合法性
            if (phoneLen != 11 ){
                layer.msg('请输入正确的手机号')
                return false;
            }

            // 按钮倒计时
            $('#yanzhengmaBtn').html(60);
            $('#yanzhengmaBtn').css({background:'#999',border:'#999'})
            var yanzheng = setInterval(function () {
                var s = $('#yanzhengmaBtn').html();
                if(s==0){
                    $('#yanzhengmaBtn').html('发送')
                    $('#yanzhengmaBtn').css({background:'#dd514c',border:'#dd514c'})
                    clearInterval(yanzheng);
                }else{
                    $('#yanzhengmaBtn').html(s-1)
                }
            },1000)

            // 发送短信
            // 准备短信接口相关数据
            var date= new Date();
            var nowtime = date.getFullYear().toString()+((date.getMonth()+1).toString().length==1?0+(date.getMonth()+1).toString():(date.getMonth()+1).toString())+(date.getDate().toString().length==1?0+date.getDate().toString():date.getDate().toString())+(date.getHours().toString().length==1?0+date.getHours().toString():date.getHours().toString())+(date.getMinutes().toString().length ==1?0+date.getMinutes().toString():date.getMinutes().toString())+(date.getSeconds().toString().length==1?0+date.getSeconds().toString():date.getSeconds().toString());

            var AuthorizationStr = 'N00000014371:'+nowtime;
            var Authorization = window.btoa(AuthorizationStr);

            var sigStr = "N0000001437153e67950-6774-11e7-a03d-25548cb1958d" + nowtime;
            var sig = calcMD5(sigStr).toUpperCase();

            yzmStr = parseInt(Math.random()*(100000-999999+1)+999999);
            console.log(111223344,yzmStr);
            yzm = calcMD5(yzmStr); // 随机验证码

            console.log(1111,yzm);

            var jsonData = '{"password":"YLHdmFoX7C","num":"'+phone+'","templateNum":"6","var1":"'+yzmStr+'","var2":"3"}';

            $.ajax({
                headers:{
                    "Accept":'application/json',
                    "Authorization":Authorization,
                    "Content-Type":'application/json;charset=utf-8'
                },
                url: 'http://apis.7moor.com/v20160818/sms/sendInterfaceTemplateSms/N00000014371?sig='+sig,
                type: 'POST',
                dataType:'json',
                data: jsonData,
                success:function(data){
                    console.log(data);
                }
            })
        }


    }

function save() {
    // 判断验证码是否正确
    var yzmInput = $('#yanzmtxt').val();
    console.log(22222,yzmInput);
    var yanzhengma = calcMD5(parseInt(yzmInput));
    console.log(yanzhengma,yzm);
    if (yzmStr!=yzmInput){
        layer.msg('验证码错误');
        return false;
    }

    $.ajax({
        url: WWW_URL+'/user/resetPassword',
        type: 'post',
        headers:HEADER,
        data: {
            password:$('#password').val().toString(),
            phone:$('.phone').val()
        },
        success:function (data) {
            layer.msg('修改成功');
            setTimeout(function () {
                window.location.href = './my.html';
            },1000)
        }
            
    })
    
}
    
    
</script>

</html>
